<?php
$js_code = file_get_contents("php://input");
$appid = "";
$secret = "";
$grant_type = "authorization_code";

$url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $js_code . "&grant_type=" . $grant_type;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if($response === false){
    echo "cURL Error: " . curl_error($ch);
} else {
    $data = json_decode($response, true);
    if(isset($data['session_key'])){
        unset($data['session_key']);
        $updated_response = json_encode($data);
        echo $updated_response;
    } 
}
curl_close($ch);
?>
